<template>
  <div>
    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="方向名称">
          <el-input v-model="formInline.name" placeholder="方向名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="toAdd">新增</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="tableData"
      >
        <el-table-column
          prop="id"
          label="编号" >
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          >
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100">
          <template v-slot:="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
            <el-button type="text" size="small" @click="delOne(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="formInline.page"
        :page-sizes="[1, 2, 3, 4]"
        :page-size="formInline.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

      <el-dialog title="方向信息" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="方向编号" :label-width="formLabelWidth">
            <el-input v-model="form.id" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="方向名称" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="toEdit">确 定</el-button>
        </div>
      </el-dialog>



    </el-card>

  </div>
</template>
<script>
  export default {
    data(){
      return {
        tableData:[],
        formInline: {
          name: '',
          page:1,
          size:5
        },
        form:{
          id:"",
          name:""
        },
        total:2,
        dialogFormVisible:false,
        formLabelWidth:'120px'

      }
    },
    methods:{
      delOne(id){
        this.$confirm('确定删除嘛', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.get("stu/delete?id="+id).then((resp)=>{

            this.showList();
          })
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

      },
      toEdit(){
        this.$axios.post("stu/update",this.form).then((resp)=>{
          this.$message({
            message: '恭喜你，修改成功',
            type: 'success'
          });

        })
        this.dialogFormVisible=false;
        this.showList();
      },
      handleClick(row){
            this. dialogFormVisible=true;
            this.form.id=row.id;
             this.form.name=row.name;

      },
      toAdd(){
        this.$router.push("vueAdd")
      },
      showList(){
        this.$axios.post("stu/findPage",this.formInline).then((resp)=>{
          this.tableData=resp.data.data.records
          this.total=resp.data.data.total
        })
      },
      handleSizeChange(val) {
        // // console.log(`每页 ${val} 条`);
        // this.formInline.size=val;
        // this.$axios.get("stu/page?page="+this.currentPage4+'&size='+this.size).then((res)=>{
        //   this.tableData=res.data.data.records;
        //   this.page=res.data.data.total;
        // })
        this.formInline.size=val;
        this.showList();
      },
      handleCurrentChange(val) {
        // this.formInline.currentPage4=val;
        // // console.log(`当前页: ${val}`);
        // this.$axios.get("stu/page?page="+this.currentPage4+'&size='+this.size).then((res)=>{
        //   this.tableData=res.data.data.records;
        //   this.page=res.data.data.total;
        // })
        this.formInline.page=val;
        this.showList();
      },
      onSubmit(){
        this.formInline.page=1;
        this.showList();

        // this.$axios.post("stu/searchVo",this.formInline).then((resp)=>{
        //       this.tableData=resp.data.data;
        // })
      }

    },
    created() {
      this.showList();
    }
  }
</script>
<style>

</style>
